
#include "../include/types.h"
#include "../include/monitor.h"
#include "../include/descr_tables.h"
#include "../include/paging.h"
#include "../include/dma.h"
#include "../include/task.h"
#include "../include/timer.h"
#include "../include/keyboard.h"
#include "../include/ide.h"
#include "../include/ext2.h"
#include "../include/console.h"

int main(){
	int i, j;
	
	init_monitor();
	
	monitor_clear();
	
	monitor_write("\n");
	monitor_color(LIGHT_BLUE);
	monitor_write("             CrazyMonkey OS             \n");
	monitor_color(DEFAULT_COLOR);
	monitor_write("\n");
	
	monitor_color(GREY);
	monitor_write("                     M .D               \n");
	monitor_write("               7MMNOMOMMM~              \n");
	monitor_write("            NZIIIIIIIIIIIIIM8           \n");
	monitor_write("          $OIIIIIIIIIIIIIIIIIM          \n");
	monitor_write("         M?IIIIIIIIIIIIIIIIIII8,        \n");
	monitor_write("         IIII~:::::?II:::::+IIIM        \n");
	monitor_write("  MN:,:8MIII::::::::=::::::::IIIMN:,,8M \n");
	monitor_write(" M:::,::MII::::::::::::::::::~IIM:,,:::M\n");
	monitor_write(" O::$~~:DII:::,:::::::::::,:::III:~~~::?\n");
	monitor_write(" M:::~~:8I::::MM:::::::::MM::::II~~~~::M\n");
	monitor_write("  M,::~~MI,::::::+7:::ND,::::::II=~::,M \n");
	monitor_write("    M,::MM:::::::::N,D:,::,:::,88=:,N.  \n");
	monitor_write("       D,::::::::::::::::::::::::M      \n");
	monitor_write("       M:::::::::::::::::::M,::::M      \n");
	monitor_write("       M:::::::::::::::::::M:::::M      \n");
	monitor_write("       ,$::::::::::::::::~M:::::I       \n");
	monitor_write("         Z::::::IMZ77NMM:::::::M        \n");
	monitor_write("          DN::::::::::::::::,M,         \n");
	monitor_write("             8MN~,:::::,~MM=            \n");
	monitor_write("                   ...                  \n");
	monitor_color(DEFAULT_COLOR);
	monitor_write("\n");

	/* Load */
	monitor_color(LIGHT_BLUE);
	monitor_write("              Loading");
	for (i = 1; i < 6; i++) {
		for (j = 1; j < 50000000; j++) ;
		monitor_write(".");
	}
	monitor_color(DEFAULT_COLOR);
	
  monitor_clear();
  monitor_write("Initialazing paging: ");
  if(!init_paging()){
		monitor_color(RED);
    monitor_write("ERROR\n");
		monitor_color(DEFAULT_COLOR);
  }
	monitor_color(GREEN);
  monitor_write("OK\n");
	monitor_color(DEFAULT_COLOR);
  
  monitor_write("Initialazing GDT & IDT: ");
  if(!init_descriptor_tables()){
		monitor_color(RED);
    monitor_write("ERROR\n");
		monitor_color(DEFAULT_COLOR);
  }
	monitor_color(GREEN);
  monitor_write("OK\n");
	monitor_color(DEFAULT_COLOR);
  monitor_write("Initialazing DMA: ");
  if(!init_dma()){
		monitor_color(RED);
    monitor_write("ERROR\n");
		monitor_color(DEFAULT_COLOR);
  }
	monitor_color(GREEN);
  monitor_write("OK\n"); 
	monitor_color(DEFAULT_COLOR);

	monitor_write("Initialazing keyboard: ");
  init_keyboard();
	monitor_color(GREEN);
  monitor_write("OK\n");
	monitor_color(DEFAULT_COLOR);
  
	monitor_write("Initialazing multitasking: ");
	init_multitasking();
	monitor_color(GREEN);
  monitor_write("OK\n");
	monitor_color(DEFAULT_COLOR);
	
	monitor_write("Initialazing timer: ");
  init_timer();
	monitor_color(GREEN);
  monitor_write("OK\n");
	monitor_color(DEFAULT_COLOR);
	
  asm volatile("sti");
	
  return 0;
}
